package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.thread.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.MemberReservationService;
import com.zzyl.nursing.vo.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController{

    @Autowired
    private MemberReservationService memberReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        Integer count = memberReservationService.getCancelledReservationCount(userId);
        System.out.println("------" + userId);
        return R.ok(count);
    }

    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation)
    {
        return toAjax(memberReservationService.insertReservation(reservation));
    }

    @GetMapping("/page")
    @ApiOperation("预约相关分页")
    public AjaxResult list(Reservation reservation){
        startPage();
        List<Reservation> list = memberReservationService.list(reservation);
        return  success(getDataTable(list));
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@PathVariable Long id){
        memberReservationService.cancel(id);
        return success();
    }

    @GetMapping("/countByTime")
    public AjaxResult countByTime(Long time){
       List<CountByTimeVo> list  = memberReservationService.countByTime(time);
        return success(list);
    }

}